package com.jz.community.modulemine.ui.view;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jz.community.basecomm.utils.BaseSpUtils;
import com.jz.community.modulemine.R;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;

/**
 * Created by Admin on 2018/3/28 0028.
 */

public class NoticeOpenDialog extends QMUIDialog {

    LinearLayout notice_back;
    TextView notice_btn;
    Context context;

    public NoticeOpenDialog(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.module_mine_dialog_open_notice);
        //关闭弹框
        notice_back = findViewById(R.id.notice_back);
        //开启推送
        notice_btn = findViewById(R.id.notice_btn);
        addListener();
    }

    private void addListener() {

        notice_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseSpUtils.put(context, "isNotice", "1");
                dismiss();
            }
        });

        notice_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 进入设置系统应用权限界面
                BaseSpUtils.put(context, "isNotice", "1");
                if (Build.VERSION.SDK_INT >= 26) {
                    //android 8.0引导
                    Intent intent = new Intent();
                    intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                    intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName());
                    context.startActivity(intent);
                } else if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 26) {
                    //android 5.0-7.0
                    Intent intent = new Intent();
                    intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                    intent.putExtra("app_package", context.getPackageName());
                    intent.putExtra("app_uid", context.getApplicationInfo().uid);
                    context.startActivity(intent);
                } else {
                    Intent intent = new Intent();
                    intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                    intent.setData(Uri.fromParts("package", context.getPackageName(), null));
                    context.startActivity(intent);
                }
                dismiss();
            }
        });
    }
}
